package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.Reply;
import dao.ReplyDao;

public class ReplyDaoImpl extends BaseDao implements ReplyDao {

	@Override
	public Integer selectReplybyid(Integer id) {
		try {
			Object query2 = query.query("select * from reply where replyid=?", id, new BeanHandler<Reply>(Reply.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer deleteReplybyid(Integer id) {
		try {
			return query.update("delete from reply where replyid=?", id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updateReply(Reply info) {
		String sql = "update reply set userid=?,replycontent=?,replytoid=?,replytype=?,type=?,time=? where replyid=?";
		try {
			return query.update(sql, info.getUserid(), info.getReplycontent(), info.getReplytoid(), info.getReplytype(),
					info.getType(), info.getTime());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addReply(Reply info) {
		String sql = "insert into reply(userid,replycontent,replytoid,replytype,type,time) VALUES(?,?,?)";
		try {
			return query.update(sql, info.getUserid(), info.getReplycontent(), info.getReplytoid(), info.getReplytype(),
					info.getType(), info.getTime());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

}
